package router

import (
	"ci-control-backend/common/httpx"
	"ci-control-backend/middleware"
	"github.com/gin-contrib/sessions"
	"github.com/gin-contrib/sessions/cookie"
	"github.com/gin-gonic/gin"
)

// SetupRoutes 设置路由
func SetupRoutes(r *gin.Engine) {
	// 设置用户模块的路由
	SetupUserRoutes(r)

	// 设置主机模块的路由
	SetupHostRoutes(r)

	// 设置计划模块的路由
	SetupPlanRoutes(r)

	// 设置记录模块的路由
	SetupRecordRoutes(r)
}

// SetupSession 设置session中间件
func SetupSession(r *gin.Engine) {
	// 配置session中间件
	store := cookie.NewStore([]byte("secret"))
	r.Use(sessions.Sessions("mysession", store))
}

// SetupRecover 设置全局异常拦截器
func SetupRecover(r *gin.Engine) {
	r.Use(httpx.Middleware(middleware.Recover))
}
